import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.mail.javamail.MimeMessageHelper;

import javax.mail.internet.MimeMessage;

public class TestSpringMail {
    public static void main(String[] args) throws Exception {
        ApplicationContext ioc=new ClassPathXmlApplicationContext("spring/spring-*.xml");
        JavaMailSenderImpl javaMailSender=(JavaMailSenderImpl)ioc.getBean("javaMailSenderImpl");
        javaMailSender.setDefaultEncoding("UTF-8");
        MimeMessage mail = javaMailSender.createMimeMessage();//一封邮件
        MimeMessageHelper helper=new MimeMessageHelper(mail);
        helper.setSubject("哈哈哈......");//邮件标题
        StringBuilder context=new StringBuilder();
        String param="I love you!";
        context.append("<a href='http://www.baidu.com'>"+param+"</a>");
        helper.setText(context.toString(),true);
        helper.setFrom("test@atguigu.com");
        helper.setTo("admin@atguigu.com");
        javaMailSender.send(mail);


    }
}
